package com.zq.im.room.dao;

import com.zq.im.room.entity.Message;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;

/**
 * Created by 张强 869518570@qq.com on 2020/9/22
 */
@Dao
public interface MessageDao {

    /**
     * flowable 会一直观察数据库的变化,发生变化就会从新读取数据
     * 查出所有的这两个人的对话
     * @param sendUserId
     * @param acceptUserId
     * @return
     */
    @Query("select * from chat_msg where (send_user_id = :sendUserId and accept_user_id = :acceptUserId) or (send_user_id = " +
            ":acceptUserId and accept_user_id = :sendUserId) order by create_time ")
    Flowable<List<Message>> getMessage(String sendUserId, String acceptUserId);


    /**
     * 新消息来,把这条消息存起来
     * 插入一条消息
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Completable insert(Message message);


    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Completable insertAll(List<Message> messages);




}
